package com.test.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.test.common.R;
import com.test.entity.SysDepartment;
import com.test.service.SysDepartmentService;

@RestController
@RequestMapping("/sys/depart")
public class SysDepartController extends AbstractController {

	@Resource
	private SysDepartmentService sysDepartmentService;

	/**
	 * 获取部门列表
	 * 
	 * @param params
	 * @return
	 */
	@RequestMapping("/list")
	public List<SysDepartment> listDepartment(@RequestParam Map<String, Object> params) {
		return sysDepartmentService.listDepartment(params);
	}

	/**
	 * 新增部门信息
	 * 
	 * @param department
	 * @return
	 */
	@RequestMapping("/save")
	public R saveDepartment(@RequestBody SysDepartment department) {
		return sysDepartmentService.saveDepartment(department);
	}

	/**
	 * 更新部门信息
	 * 
	 * @param department
	 * @return
	 */
	@RequestMapping("/update")
	public R updateDepartment(@RequestBody SysDepartment department) {
		return sysDepartmentService.updateDepartment(department);
	}

	/**
	 * 根据部门编码删除部门信息
	 * 
	 * @param depart_code
	 * @return
	 */
	@RequestMapping("/remove")
	public R removeDepartment(@RequestBody String depart_code) {
		return sysDepartmentService.removeByDepartCode(depart_code);
	}

	/**
	 * 获取所有部门信息
	 * 
	 * @return
	 */
	@RequestMapping("/select")
	public R listDepartmentTree() {
		return sysDepartmentService.listDepartmentTree();
	}

	@RequestMapping("/info")
	public R listDepartmentInfo(@RequestBody String depart_code) {
		SysDepartment department = new SysDepartment();
		department.setDepart_code(depart_code);
		return sysDepartmentService.listDepartmentByParameter(department);
	}
}
